package com.warm.pump.module.monitor.inform.impl;

import com.warm.pump.frame.util.SpringBeanUtil;
import com.warm.pump.frame.util.StringUtil;
import com.warm.pump.module.monitor.bean.po.gen.MisfireInform;
import com.warm.pump.module.monitor.inform.InformModeWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

public class EmailWrapper implements InformModeWrapper {
    private static final Logger log = LoggerFactory.getLogger(EmailWrapper.class);

    @Override
    public void send(MisfireInform failureDeal, String sendContent, String title) {
        JavaMailSender mailSender = SpringBeanUtil.getBean(JavaMailSender.class);

        //3.发送邮件
        String emailTo = failureDeal.getContactName();
        if (emailTo == null) {
            throw new RuntimeException("contactName配置有误，联系方式配置为空！！");
        }
        String[] emailTos = StringUtil.getStringtoArray(emailTo, ";");
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("3261676817@qq.com");
        message.setTo(emailTos);
        message.setSubject("作业任务失败预警");
        message.setText(sendContent);

        mailSender.send(message);

    }
}
